package com.fgxia.admin.controller.operation;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.fgxia.admin.service.IAdminWaybillService;
import com.ruoyi.business.domain.bo.admin.*;
import com.ruoyi.business.domain.vo.admin.AdminWaybillAddVo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.Type2Group;
import com.ruoyi.common.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 运单管理运单
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/operation/waybill")
public class AdminWaybillController extends BaseController {

    private final IAdminWaybillService waybillService;

    /**
     * 查询运单详情，根据订单id
     */
    // @SaCheckPermission("waybill:waybill:query")
    @GetMapping(value = "/{orderId}")
    public R<AdminWaybillAddVo> getInfo(@PathVariable Long orderId) {
        return R.ok(waybillService.selectWaybillById(orderId));
    }

    /**
     * 新增运单
     */
    @RepeatSubmit
    @SaCheckPermission("waybill:waybill:add")
    @Log(title = "运单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AdminWaybillAddBo waybill) {
        return toAjax(waybillService.insertWaybill(waybill));
    }

    /**
     * 编辑运单
     */
    @RepeatSubmit
    @SaCheckPermission("waybill:waybill:edit")
    @Log(title = "运单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AdminWaybillAddBo waybill) {
        return toAjax(waybillService.updateWaybill(waybill));
    }

    /**
     * 定位打卡
     */
    @RepeatSubmit
    @SaCheckPermission("waybill:waybill:location")
    @Log(title = "运单管理", businessType = BusinessType.INSERT)
    @PostMapping("/location")
    public R<Void> location(@Validated @RequestBody AdminLocationAddBo location) {
        return toAjax(waybillService.insertLocation(location));
    }

    /**
     * 运单改价
     */
    @RepeatSubmit
    @SaCheckPermission("waybill:waybill:price")
    @Log(title = "运单管理", businessType = BusinessType.UPDATE)
    @PostMapping("/price")
    public R<Void> price(@Validated(Type2Group.class) @RequestBody AdminPriceEditBo price) {
        return toAjax(waybillService.updateWaybillPrice(price));
    }

    /**
     * 紧急运单
     */
    @RepeatSubmit
    @SaCheckPermission("waybill:urgent:submit")
    @Log(title = "运单管理", businessType = BusinessType.UPDATE)
    @PutMapping("/urgent")
    public R<Void> urgent(@Validated @RequestBody AdminUrgentBo urgent) {
        return toAjax(waybillService.urgentWaybill(urgent));
    }

    /**
     * 取消紧急运单
     */
    @RepeatSubmit
    @SaCheckPermission("waybill:urgent:cancel")
    @Log(title = "运单管理", businessType = BusinessType.UPDATE)
    @PutMapping("/urgent/cancel")
    public R<Void> cancelUrgent(@Validated @RequestBody AdminUrgentBo urgent) {
        return toAjax(waybillService.cancelUrgentWaybill(urgent));
    }

    /**
     * 上传回单
     */
    @RepeatSubmit
    @SaCheckPermission("waybill:waybill:receipt")
    @Log(title = "运单管理", businessType = BusinessType.INSERT)
    @PostMapping("/receipt")
    public R<Void> receipt(@Validated @RequestBody AdminUploadBillBo receipt) {
        return toAjax(waybillService.insertReceipt(receipt));
    }

    /**
     * 上传运单打款凭证
     */
    @RepeatSubmit
    @SaCheckPermission("waybill:waybill:payment")
    @Log(title = "运单管理", businessType = BusinessType.INSERT)
    @PostMapping("/payment")
    public R<Void> payment(@Validated @RequestBody AdminUploadBillBo payment) {
        return toAjax(waybillService.insertPayment(payment));
    }
}
